package com.moose.operator.web.service.impl.poetry;

import com.moose.operator.common.QueryWrapper;
import com.moose.operator.model.entity.PoetryItem;
import com.moose.operator.model.param.poetry.PoetrySearchParam;
import com.moose.operator.web.service.PoetryItemService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * <p>
 * Description:
 * </p>
 *
 * @author taohua
 * @version v1.0.0
 * @date 2020-12-13 21:47:21:47
 * @see com.moose.operator.web.service.impl
 */
@Service
public class PoetryItemServiceImpl implements PoetryItemService {

  @Resource
  private MongoTemplate mongoTemplate;

  @Override public List<PoetryItem> listPoetry(PoetrySearchParam searchParam) {
    Integer pageNum = searchParam.getPageNum();
    Integer pageSize = searchParam.getPageSize();

    Query query = QueryWrapper.buildPageQuery(pageNum, pageSize);
    Criteria criteria = new Criteria();
    Integer tagId = searchParam.getTagId();
    if (null != searchParam.getTagId()) {
      criteria.and("tag_arr.id").is(tagId);
    }
    query.addCriteria(criteria);
    return mongoTemplate.find(query, PoetryItem.class);
  }
}
